/**
* @description 字典模块
*/

import ds from '../components/ds'
import service, {api} from '../service/dictionary.service'
import { treer, funcer, objecter } from '@daelui/dogjs/dist/components.js'

// 服务
export default Object.assign({}, service, {
  /**
   * @function 查询环境树形数据
  */
  queryTreeEnv () {
    // 查询导航数据
    return service.queryTree({cat: 'page-envirment'}, {cache: true, buffer: true}).then(res => {
      let list = (res?.data || {}).list
      list = Array.isArray(list) ? list : []
      let arr = []
      treer.forEach({ data: list, callback: function (item, level) {
        item = objecter.clone(item)
        item.code = funcer.loop(level, ' - ') + item.code
        arr.push(item)
      }})
      return arr
    })
  }
})

export {
  api, service, ds
}
